package jmetal.problems.ddtlz;

import jmetal.core.Solution;
import jmetal.core.Variable;
import jmetal.util.JMException;

@SuppressWarnings("serial")
public class F1 extends F {

	public F1(Integer numberOfVariables, Integer cycle) {
		super(numberOfVariables, cycle);
	}

	@Override
	public void evaluate(Solution solution) throws JMException {
		Variable[] gen = solution.getDecisionVariables();
		double[] x = new double [numberOfVariables_] ;
		double[] f = new double [numberOfObjectives_];
		for(int i = 0;i < x.length;i++){
			x[i] = gen[i].getValue();
		}
		
		int k = numberOfVariables_-numberOfObjectives_+1;
		double g = 0.0;
		for(int i = numberOfObjectives_-1;i<numberOfVariables_;i++){
			g += (x[i] - 0.5)*(x[i] - 0.5) - Math.cos(20 * Math.PI * (x[i]-0.5)) ;
		}
		g = 100 * ( k+g );
	    for (int i = 0; i < numberOfObjectives_; i++){
	        f[i] = (1.0 + g) * 0.5;
	    }
	    for(int i = 0; i<numberOfObjectives_; i++){
	    	for(int j = 0;j < numberOfObjectives_-(i+1);j++){
	    		f[i] *= x[j] ;
	    	}
	    	if(i != 0){
	    		int aux = numberOfObjectives_ - (i+1);
	    		f[i] *= 1 - x[aux] ;
	    	}
	    }
	    
	    for(int i = 0;i<numberOfObjectives_;i++){
	    	solution.setObjective(i, f[i]);
	    }
	    
	}
}
